package com.htthorizon.common.core.config;


import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.env.ConfigurableEnvironment;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class LogbackConfig implements ApplicationListener<ApplicationEnvironmentPreparedEvent> {

    @Override
    public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
        ConfigurableEnvironment environment = event.getEnvironment();
        String serverPort = environment.getProperty("server.port");
        try {
            String ipAddress = InetAddress.getLocalHost().getHostAddress();
            System.setProperty("service.ip", ipAddress);
        } catch (UnknownHostException e) {
            // Handle exception and log it
        }
        System.setProperty("service.port", serverPort);
    }
}
